//
//  ExaminaColumnTopView.m
//  Coach_HaiGeEr
//
//  Created by liuchen on 2018/10/18.
//  Copyright © 2018年 海格尔. All rights reserved.
//

#import "ExaminaColumnTopView.h"
@interface ExaminaColumnTopView()
@property (nonatomic,strong) NSMutableArray *buttonsArr;
@property (nonatomic,copy) UILabel *todayLabel;
@end

@implementation ExaminaColumnTopView

- (instancetype)initWithFrame:(CGRect)frame{//180+80
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

#pragma mark ==========创建视图==========
- (void)createSubView{
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame), 180*SCALEUNIT)];
    backView.backgroundColor = [UIColor whiteColor];
    [self addSubview:backView];
    NSArray *titleArr = [NSArray arrayWithObjects:@"教练审核",@"驾校审核",@"待考试",@"历史统计", nil];
    for (int i=0; i<4; i++) {
        CGFloat size = 120*SCALEUNIT;
        CGFloat edge = 50*SCALEUNIT;
        CGFloat interval = (CGRectGetWidth(self.frame)-edge*2-size*4)/3.0;
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        btn.showsTouchWhenHighlighted  = YES;
        [btn setTitle: [titleArr objectAtIndex:i] forState:UIControlStateNormal];
        [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
        [btn.titleLabel setFont:[UIFont systemFontOfSize:LoginFont-4]];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [btn setBackgroundColor:[UIColor colorWithHexString:@"#676fe9"]];
        btn.frame = CGRectMake(0, 0, size, size);
        btn.center = CGPointMake((edge+size/2.0)+(size+interval)*i, CGRectGetHeight(backView.frame)/2.0);
        btn.tag = 10000+i;
        [btn addTarget:self action:@selector(btnChange:) forControlEvents:UIControlEventTouchUpInside];
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, size, size) byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(size/2.0, size/2.0)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = CGRectMake(0, 0, size, size);
        //maskLayer.lineWidth = SCALEUNIT;
        //maskLayer.strokeColor = [UIColor colorWithHexString:@""].CGColor;
        //maskLayer.fillColor = [UIColor clearColor].CGColor;
        maskLayer.path = maskPath.CGPath;
        btn.layer.mask = maskLayer;
        [backView addSubview:btn];
        [self.buttonsArr addObject:btn];
    }
    
    UILabel *todayLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(backView.frame), CGRectGetWidth(backView.frame), 80*SCALEUNIT)];
    todayLabel.backgroundColor = [UIColor colorWithHexString:@"#eeeeee"];
    todayLabel.textColor = [UIColor colorWithHexString:@"#282828"];
    todayLabel.font = [UIFont systemFontOfSize:LoginFont-1];
    todayLabel.textAlignment = NSTextAlignmentCenter;
    todayLabel.text = @"今日考试";
    _todayLabel = todayLabel;
    [self addSubview:self.todayLabel];
}

#pragma mark ==========按钮方法==========
- (void)btnChange:(UIButton *)btn{
    self.block(btn.tag-10000);
}

#pragma mark ==========懒加载==========
- (NSMutableArray *)buttonsArr{
    if (!_buttonsArr) {
        _buttonsArr = [[NSMutableArray alloc] init];
    }
    return _buttonsArr;
}





@end
